home *** CD-ROM | disk | FTP | other *** search
/ Aminet 21 / Aminet 21 (1997)(GTI - Schatztruhe)[!][Oct 1997].iso / Aminet / gfx / show / gs_src_gs.lha / gs5.03 / gdevprn.h < prev    next >
C/C++ Source or Header  |  1997-07-18  |  14KB  |  375 lines

  1. /* Copyright (C) 1989, 1995, 1996, 1997 Aladdin Enterprises.  All rights reserved.
  2.   
  3.   This file is part of Aladdin Ghostscript.
  4.   
  5.   Aladdin Ghostscript is distributed with NO WARRANTY OF ANY KIND.  No author
  6.   or distributor accepts any responsibility for the consequences of using it,
  7.   or for whether it serves any particular purpose or works at all, unless he
  8.   or she says so in writing.  Refer to the Aladdin Ghostscript Free Public
  9.   License (the "License") for full details.
  10.   
  11.   Every copy of Aladdin Ghostscript must include a copy of the License,
  12.   normally in a plain ASCII text file named PUBLIC.  The License grants you
  13.   the right to copy, modify and redistribute Aladdin Ghostscript, but only
  14.   under certain conditions described in the License.  Among other things, the
  15.   License requires that the copyright notice and this notice be preserved on
  16.   all copies.
  17. */
  18.  
  19. /* gdevprn.h */
  20. /* Common header file for memory-buffered printers */
  21.  
  22. #ifndef gdevprn_INCLUDED
  23. #  define gdevprn_INCLUDED
  24.  
  25. #include "memory_.h"
  26. #include "string_.h"
  27. #include "gx.h"
  28. #include "gserrors.h"
  29. #include "gsmatrix.h"            /* for gxdevice.h */
  30. #include "gsutil.h"            /* for memflip8x8 */
  31. #include "gxdevice.h"
  32. #include "gxdevmem.h"
  33. #include "gxclist.h"
  34. #include "gsparam.h"
  35.  
  36. /*
  37.  * Define the parameters for the printer rendering method.
  38.  * If the entire bitmap fits in PRN_MAX_BITMAP, and there is at least
  39.  * PRN_MIN_MEMORY_LEFT memory left after allocating it, render in RAM,
  40.  * otherwise use a command list with a size of PRN_BUFFER_SPACE.
  41.  * (These are parameters that can be changed by a client program.)
  42.  */
  43. /* Define parameters for machines with little dinky RAMs.... */
  44. #define PRN_MAX_BITMAP_SMALL 32000
  45. #define PRN_BUFFER_SPACE_SMALL 25000
  46. #define PRN_MIN_MEMORY_LEFT_SMALL 32000
  47. /* Define parameters for machines with great big hulking RAMs.... */
  48. #define PRN_MAX_BITMAP_LARGE 10000000L
  49. #define PRN_BUFFER_SPACE_LARGE 1000000L
  50. #define PRN_MIN_MEMORY_LEFT_LARGE 500000L
  51. /* Define parameters valid on all machines. */
  52. #define PRN_MIN_BUFFER_SPACE 10000    /* give up if less than this */
  53. /* Now define conditional parameters. */
  54. #if arch_small_memory
  55. #  define PRN_MAX_BITMAP PRN_MAX_BITMAP_SMALL
  56. #  define PRN_BUFFER_SPACE PRN_BUFFER_SPACE_SMALL
  57. #  define PRN_MIN_MEMORY_LEFT PRN_MIN_MEMORY_LEFT_SMALL
  58. #else
  59. /****** These should really be conditional on gs_debug_c('.') if
  60.  ****** DEBUG is defined, but they're used in static initializers,
  61.  ****** so we can't do it.
  62.  ******/
  63. #  if 0 /****** #  ifdef DEBUG ******/
  64. #    define PRN_MAX_BITMAP\
  65.        (gs_debug_c('.') ? PRN_MAX_BITMAP_SMALL : PRN_MAX_BITMAP_LARGE)
  66. #    define PRN_BUFFER_SPACE\
  67.        (gs_debug_c('.') ? PRN_BUFFER_SPACE_SMALL : PRN_BUFFER_SPACE_LARGE)
  68. #    define PRN_MIN_MEMORY_LEFT\
  69.        (gs_debug_c('.') ? PRN_MIN_MEMORY_LEFT_SMALL : PRN_MIN_MEMORY_LEFT_LARGE)
  70. #  else
  71. #    define PRN_MAX_BITMAP PRN_MAX_BITMAP_LARGE
  72. #    define PRN_BUFFER_SPACE PRN_BUFFER_SPACE_LARGE
  73. #    define PRN_MIN_MEMORY_LEFT PRN_MIN_MEMORY_LEFT_LARGE
  74. #  endif
  75. #endif
  76.  
  77. /* Define the abstract type for a printer device. */
  78. typedef struct gx_device_printer_s gx_device_printer;
  79.  
  80. /*
  81.  * Define the special procedures for band devices.
  82.  */
  83. typedef struct gx_printer_device_procs_s {
  84.  
  85.     /*
  86.      * Print the page on the output file.  Required only for devices
  87.      * where output_page is gdev_prn_output_page; ignored for other
  88.      * devices.
  89.      */
  90.  
  91. #define dev_proc_print_page(proc)\
  92.   int proc(P2(gx_device_printer *, FILE *))
  93.     dev_proc_print_page((*print_page));
  94.  
  95.     /* Print the page on the output file, with a given # of copies. */
  96.  
  97. #define dev_proc_print_page_copies(proc)\
  98.   int proc(P3(gx_device_printer *, FILE *, int))
  99.     dev_proc_print_page_copies((*print_page_copies));
  100.  
  101.     /* Initialize the memory device for a page or a band. */
  102.     /* (The macro definition is in gxdevice.h.) */
  103.  
  104.     dev_proc_make_buffer_device((*make_buffer_device));
  105.  
  106. } gx_printer_device_procs;
  107.  
  108. /* ------ Printer device definition ------ */
  109.  
  110. /* Structure for generic printer devices. */
  111. /* This must be preceded by gx_device_common. */
  112. /* Printer devices are actually a union of a memory device */
  113. /* and a clist device, plus some additional state. */
  114. #define prn_fname_sizeof 80
  115. typedef struct gdev_prn_space_params_s {
  116.     long MaxBitmap;            /* max size of non-buffered bitmap */
  117.     long BufferSpace;        /* space to use for buffer */
  118.     gx_band_params band;        /* see gxclist.h */
  119. } gdev_prn_space_params;
  120. #define gx_prn_device_common\
  121.     byte skip[max(sizeof(gx_device_memory), sizeof(gx_device_clist)) -\
  122.           sizeof(gx_device) + sizeof(double) /* padding */];\
  123.     gx_printer_device_procs printer_procs;\
  124.         /* ------ Device parameters that must be set ------ */\
  125.         /* ------ before calling the device open routine. ------ */\
  126.     gdev_prn_space_params space_params;\
  127.     char fname[prn_fname_sizeof];    /* OutputFile */\
  128.         /* ------ Other device parameters ------ */\
  129.     int NumCopies;\
  130.       bool NumCopies_set;\
  131.     bool OpenOutputFile;\
  132.     bool Duplex;\
  133.       int Duplex_set;        /* -1 = not supported */\
  134.         /* ------ End of parameters ------ */\
  135.     bool file_is_new;        /* true iff file just opened */\
  136.     FILE *file;            /* output file */\
  137.     long buffer_space;    /* amount of space for clist buffer, */\
  138.                     /* 0 means not using clist */\
  139.     byte *buf;            /* buffer for rendering */\
  140.     gx_device_procs orig_procs    /* original (std_)procs */
  141.  
  142. /* The device descriptor */
  143. struct gx_device_printer_s {
  144.     gx_device_common;
  145.     gx_prn_device_common;
  146. };
  147.  
  148. /* Macro for casting gx_device argument */
  149. #define prn_dev ((gx_device_printer *)dev)
  150.  
  151. /* Define a typedef for the sake of ansi2knr. */
  152. typedef dev_proc_print_page((*dev_proc_print_page_t));
  153.  
  154. /* Standard device procedures for printers */
  155. dev_proc_open_device(gdev_prn_open);
  156. dev_proc_output_page(gdev_prn_output_page);
  157. dev_proc_close_device(gdev_prn_close);
  158. #define gdev_prn_map_rgb_color gx_default_b_w_map_rgb_color
  159. #define gdev_prn_map_color_rgb gx_default_b_w_map_color_rgb
  160. dev_proc_get_params(gdev_prn_get_params);
  161. dev_proc_put_params(gdev_prn_put_params);
  162.  
  163. /* Macro for generating procedure table */
  164. #define prn_procs(p_open, p_output_page, p_close)\
  165.   prn_color_procs(p_open, p_output_page, p_close, gdev_prn_map_rgb_color, gdev_prn_map_color_rgb)
  166. #define prn_params_procs(p_open, p_output_page, p_close, p_get_params, p_put_params)\
  167.   prn_color_params_procs(p_open, p_output_page, p_close, gdev_prn_map_rgb_color, gdev_prn_map_color_rgb, p_get_params, p_put_params)
  168. #define prn_color_procs(p_open, p_output_page, p_close, p_map_rgb_color, p_map_color_rgb)\
  169.   prn_color_params_procs(p_open, p_output_page, p_close, p_map_rgb_color, p_map_color_rgb, gdev_prn_get_params, gdev_prn_put_params)
  170. /* See gdev_prn_open for explanation of the NULLs below. */
  171. #define prn_color_params_procs(p_open, p_output_page, p_close, p_map_rgb_color, p_map_color_rgb, p_get_params, p_put_params) {\
  172.     p_open,\
  173.     NULL,    /* get_initial_matrix */\
  174.     NULL,    /* sync_output */\
  175.     p_output_page,\
  176.     p_close,\
  177.     p_map_rgb_color,\
  178.     p_map_color_rgb,\
  179.     NULL,    /* fill_rectangle */\
  180.     NULL,    /* tile_rectangle */\
  181.     NULL,    /* copy_mono */\
  182.     NULL,    /* copy_color */\
  183.     NULL,    /* draw_line */\
  184.     NULL,    /* get_bits */\
  185.     p_get_params,\
  186.     p_put_params,\
  187.     NULL,    /* map_cmyk_color */\
  188.     NULL,    /* get_xfont_procs */\
  189.     NULL,    /* get_xfont_device */\
  190.     NULL,    /* map_rgb_alpha_color */\
  191.     gx_page_device_get_page_device,\
  192.     NULL,    /* get_alpha_bits */\
  193.     NULL,    /* copy_alpha */\
  194.     NULL,    /* get_band */\
  195.     NULL,    /* copy_rop */\
  196.     NULL,    /* fill_path */\
  197.     NULL,    /* stroke_path */\
  198.     NULL,    /* fill_mask */\
  199.     NULL,    /* fill_trapezoid */\
  200.     NULL,    /* fill_parallelogram */\
  201.     NULL,    /* fill_triangle */\
  202.     NULL,    /* draw_thin_line */\
  203.     NULL,    /* begin_image */\
  204.     NULL,    /* image_data */\
  205.     NULL,    /* end_image */\
  206.     NULL,    /* strip_tile_rectangle */\
  207.     NULL,    /* strip_copy_rop, */\
  208.     NULL    /* get_clipping_box */\
  209. }
  210.  
  211. /* The standard printer device procedures */
  212. /* (using gdev_prn_open/output_page/close). */
  213. extern gx_device_procs prn_std_procs;
  214.  
  215. /*
  216.  * Define macros for generating the device structure,
  217.  * analogous to the std_device_body macros in gxdevice.h
  218.  * Note that the macros are broken up so as to be usable for devices that
  219.  * add further initialized state to the printer device.
  220.  *
  221.  * The 'margin' values provided here specify the unimageable region
  222.  * around the edges of the page (in inches), and the left and top margins
  223.  * also specify the displacement of the device (0,0) point from the
  224.  * upper left corner.  We should provide macros that allow specifying
  225.  * all 6 values independently, but we don't yet.
  226.  */
  227. #define prn_device_body_rest_(print_page)\
  228.      { 0 },        /* std_procs */\
  229.      { 0 },        /* skip */\
  230.      { print_page,\
  231.        gx_default_print_page_copies,\
  232.        gx_default_make_buffer_device\
  233.      },\
  234.      { PRN_MAX_BITMAP, PRN_BUFFER_SPACE,\
  235.          { band_params_initial_values }\
  236.      },\
  237.      { 0 },        /* fname */\
  238.     1, 0/*false*/,    /* NumCopies[_set] */\
  239.     0/*false*/,    /* OpenOutputFile */\
  240.     0/*false*/, -1,    /* Duplex[_set] */\
  241.     0/*false*/, 0, 0, 0, { 0 }    /* ... orig_procs */
  242.  
  243. /* The Sun cc compiler won't allow \ within a macro argument list. */
  244. /* This accounts for the short parameter names here and below. */
  245. #define prn_device_margins_body(dtype, procs, dname, w10, h10, xdpi, ydpi, lo, to, lm, bm, rm, tm, ncomp, depth, mg, mc, dg, dc, print_page)\
  246.     std_device_full_body(dtype, &procs, dname,\
  247.       (int)((long)(w10) * (xdpi) / 10),\
  248.       (int)((long)(h10) * (ydpi) / 10),\
  249.       xdpi, ydpi,\
  250.       ncomp, depth, mg, mc, dg, dc,\
  251.       -(lo) * (xdpi), -(to) * (ydpi),\
  252.       (lm) * 72.0, (bm) * 72.0,\
  253.       (rm) * 72.0, (tm) * 72.0\
  254.     ),\
  255.     prn_device_body_rest_(print_page)
  256.  
  257. #define prn_device_body(dtype, procs, dname, w10, h10, xdpi, ydpi, lm, bm, rm, tm, ncomp, depth, mg, mc, dg, dc, print_page)\
  258.   prn_device_margins_body(dtype, procs, dname, w10, h10, xdpi, ydpi,\
  259.     lm, tm, lm, bm, rm, tm, ncomp, depth, mg, mc, dg, dc, print_page)
  260.  
  261. #define prn_device_std_margins_body(dtype, procs, dname, w10, h10, xdpi, ydpi, lo, to, lm, bm, rm, tm, color_bits, print_page)\
  262.     std_device_std_color_full_body(dtype, &procs, dname,\
  263.       (int)((long)(w10) * (xdpi) / 10),\
  264.       (int)((long)(h10) * (ydpi) / 10),\
  265.       xdpi, ydpi, color_bits,\
  266.       -(lo) * (xdpi), -(to) * (ydpi),\
  267.       (lm) * 72.0, (bm) * 72.0,\
  268.       (rm) * 72.0, (tm) * 72.0\
  269.     ),\
  270.     prn_device_body_rest_(print_page)
  271.  
  272. #define prn_device_std_body(dtype, procs, dname, w10, h10, xdpi, ydpi, lm, bm, rm, tm, color_bits, print_page)\
  273.   prn_device_std_margins_body(dtype, procs, dname, w10, h10, xdpi, ydpi,\
  274.     lm, tm, lm, bm, rm, tm, color_bits, print_page)
  275.  
  276. #define prn_device_margins(procs, dname, w10, h10, xdpi, ydpi, lo, to, lm, bm, rm, tm, color_bits, print_page)\
  277. { prn_device_std_margins_body(gx_device_printer, procs, dname,\
  278.     w10, h10, xdpi, ydpi, lo, to, lm, bm, rm, tm, color_bits, print_page)\
  279. }
  280.  
  281. #define prn_device(procs, dname, w10, h10, xdpi, ydpi, lm, bm, rm, tm, color_bits, print_page)\
  282.   prn_device_margins(procs, dname, w10, h10, xdpi, ydpi,\
  283.     lm, tm, lm, bm, rm, tm, color_bits, print_page)\
  284.  
  285. /* ------ Utilities ------ */
  286. /* These are defined in gdevprn.c. */
  287.  
  288. int gdev_prn_open_printer(P2(gx_device *dev, bool binary_mode));
  289. #define gdev_prn_file_is_new(pdev) ((pdev)->file_is_new)
  290. #define gdev_prn_raster(pdev) gx_device_raster((gx_device *)(pdev), 0)
  291. int gdev_prn_get_bits(P4(gx_device_printer *, int, byte *, byte **));
  292. int gdev_prn_copy_scan_lines(P4(gx_device_printer *, int, byte *, uint));
  293. int gdev_prn_close_printer(P1(gx_device *));
  294.  
  295. /* Define the InputAttributes and OutputAttributes of a device. */
  296. /* The device get_params procedure would call these. */
  297.  
  298. typedef struct input_media_s {
  299.     float PageSize[2];
  300.     const char *MediaColor;
  301.     float MediaWeight;
  302.     const char *MediaType;
  303. } input_media;
  304. #define gdev_prn_begin_input_media(plist, pdict, count)\
  305.   ((pdict)->size = (count),\
  306.    param_begin_write_dict(plist, "InputAttributes", pdict, true))
  307. int gdev_prn_input_page_size(P4(int index, gs_param_dict *pdict,
  308.   floatp width_points, floatp height_points));
  309. int gdev_prn_input_media(P3(int index, gs_param_dict *pdict,
  310.   const input_media *pim));
  311. #define gdev_prn_end_input_media(plist, pdict)\
  312.   param_end_write_dict(plist, "InputAttributes", pdict)
  313.  
  314. typedef struct output_media_s {
  315.     const char *OutputType;
  316. } output_media;
  317. #define gdev_prn_begin_output_media(plist, pdict, count)\
  318.   ((pdict)->size = (count),\
  319.    param_begin_write_dict(plist, "OutputAttributes", pdict, true))
  320. int gdev_prn_output_media(P3(int index, gs_param_dict *pdict,
  321.   const output_media *pom));
  322. #define gdev_prn_end_output_media(plist, pdict)\
  323.   param_end_write_dict(plist, "OutputAttributes", pdict)
  324.  
  325. /* The default print_page_copies procedure just calls print_page */
  326. /* the given number of times. */
  327. dev_proc_print_page_copies(gx_default_print_page_copies);
  328.  
  329. /* Define the number of scan lines that should actually be passed */
  330. /* to the device. */
  331. int gdev_prn_print_scan_lines(P1(gx_device *));
  332.  
  333. /* BACKWARD COMPATIBILITY */
  334. #define dev_print_scan_lines(dev)\
  335.   gdev_prn_print_scan_lines((gx_device *)(dev))
  336. #define gdev_mem_bytes_per_scan_line(dev)\
  337.   gdev_prn_raster((gx_device_printer *)(dev))
  338. #define gdev_prn_transpose_8x8(inp,ils,outp,ols)\
  339.   memflip8x8(inp,ils,outp,ols)
  340.  
  341. /* ------ Printer device types ------ */
  342. /**************** THE FOLLOWING CODE IS NOT USED YET. ****************/
  343.  
  344. #if 0        /**************** VMS linker gets upset ****************/
  345. extern_st(st_prn_device);
  346. #endif
  347. int    gdev_prn_initialize(P3(gx_device *, const char _ds *, dev_proc_print_page((*))));
  348. void    gdev_prn_init_color(P4(gx_device *, int, dev_proc_map_rgb_color((*)), dev_proc_map_color_rgb((*))));
  349.  
  350. #define prn_device_type(dtname, initproc, pageproc)\
  351. private dev_proc_print_page(pageproc);\
  352. device_type(dtname, st_prn_device, initproc)
  353.  
  354. /****** FOLLOWING SHOULD CHECK __PROTOTYPES__ ******/
  355. #define prn_device_type_mono(dtname, dname, initproc, pageproc)\
  356. private dev_proc_print_page(pageproc);\
  357. private int \
  358. initproc(gx_device *dev)\
  359. {    return gdev_prn_initialize(dev, dname, pageproc);\
  360. }\
  361. device_type(dtname, st_prn_device, initproc)
  362.  
  363. /****** DITTO ******/
  364. #define prn_device_type_color(dtname, dname, depth, initproc, pageproc, rcproc, crproc)\
  365. private dev_proc_print_page(pageproc);\
  366. private int \
  367. initproc(gx_device *dev)\
  368. {    int code = gdev_prn_initialize(dev, dname, pageproc);\
  369.     gdev_prn_init_color(dev, depth, rcproc, crproc);\
  370.     return code;\
  371. }\
  372. device_type(dtname, st_prn_device, initproc)
  373.  
  374. #endif                /* gdevprn_INCLUDED */
  375.